<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;

class Banner extends SortableModel
{
    use HasFactory;
    use Cachable;

    const LINK_TYPE_INSIDE = 'inside';
    const LINK_TYPE_OUTSIDE = 'outside';
    const LINK_TYPE_WEB = 'web';

    public static $linkTypeMap = [
        self::LINK_TYPE_INSIDE  => '内部小程序页面',
        self::LINK_TYPE_OUTSIDE => '外部小程序页面',
        self::LINK_TYPE_WEB => '网页页面',
    ];

    protected $fillable = [
        'title', 'sign', 'link', 'link_type', 'valid', 'order', 'image'
    ];

    protected $casts = [
        'valid' => 'boolean',
        'order' => 'integer',
    ];

    public function label()
    {
        return $this->belongsTo(BannerSign::class, 'sign', 'sign');
    }
}
